package com.hong.controller;


import com.hong.dto.UserDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@Api(value ="测试用例",tags = {"测试用例"})
@RequestMapping("test")
@RestController
public class TestController {

    private Logger logger = LoggerFactory.getLogger(TestController.class);


    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_UNCOMMITTED ,propagation = Propagation.REQUIRED)

    @ApiOperation("获取信息")
    @GetMapping("list")
    public String getInfo(UserDTO param){

        logger.info("name:{},code:{}",param.getName(),param.getCode());


        String result = String.format("name:%s,code:%d", param.getName(), param.getCode());

        return result;
    }

    @ApiOperation("获取用户详情")
    @GetMapping("{id}")
    public UserDTO  getUser(@PathVariable("id") Long id){
        UserDTO userDTO = new UserDTO();
        userDTO.setId(id);
        userDTO.setCode(1);
        userDTO.setName("王柳");
        return userDTO;
    }

    @ApiOperation("保存用户信息")
    @PostMapping("insert")
    public String saveUser(@RequestBody UserDTO param){
        logger.info("name:{},code:{}",param.getName(),param.getCode());

        return "OK";
    }


}
